package local.app;


import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import local.app.servers.StandardServer;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.util.ArrayList;
import java.util.List;

public class ProcessInfo {
    public static void main(String[] args) throws IOException, InterruptedException, JSchException {
        StandardServer server = new StandardServer("test", "127.0.0.1");
        Session session = server.setConfigAndReturnSession("" ,"");
        session.connect();

        System.out.println(session.isConnected());

        ChannelExec channel = (ChannelExec) session.openChannel("exec");
        //channel.setCommand("uname -a");
        channel.setCommand("systemctl");
        channel.connect();


        InputStream in = channel.getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));

        List<String> services = new ArrayList<>();
        String line;

        while ((line = reader.readLine()) != null) {
            services.add(line);
        }


        for (String service : services) {
            System.out.println(service);
        }
        channel.disconnect();
        session.disconnect();


//        InputStream in = channel.getInputStream();
//        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
//        System.out.println(reader.readLine());
//        List<String> services = new ArrayList<>();
//        String line;
//
//        while ((line = reader.readLine()) != null) {
//            services.add(line);
//        }
//
//
//
//        for (String service : services) {
//            System.out.println(service);
//        }


    }


}
